package com.penfei.springrun.dao;


import com.penfei.springrun.domain.SecurityQuestionInfo;
import com.penfei.springrun.domain.UserInfo;
import com.penfei.springrun.domain.UserSecurityInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserDao {

    @Select("select * from user_data where id=#{id}")
    UserInfo getById(@Param("id") String id);

    @Select("select * from user_data where Phone=#{Phone}")
    UserInfo getByPhone(@Param("Phone") String Phone);

    @Select("SELECT * FROM `security_question_data`")
    List<SecurityQuestionInfo> getSecurityQuestionList();

    @Insert("insert into user_data(id,phone,password,userName) values(#{id},#{phone},#{password},#{userName})")
    int insert(UserInfo info);

    @Delete("delete from user_data where id=#{id}")
    int delete(@Param("id") String id);

    @Update("UPDATE `user_data` SET `password`=#{password}, `sessionId`=#{sessionId} where (id=#{id})")
    int update(@Param("id") String id, @Param("phone") String phone, @Param("password") String password, @Param("userName") String userName, @Param("sessionId") String sessionId);

    @Insert("INSERT INTO `user_security_question_data` (`userId`, `questionId1`, `questionId2`, `questionId3`, `answer1`, `answer2`, `answer3`) VALUES (#{userId},#{questionId1}, #{questionId2}, #{questionId3}, #{answer1}, #{answer2},#{answer3})")
    int insertSecurity(@Param("userId") String userId, @Param("questionId1") String questionId1, @Param("questionId2") String questionId2, @Param("questionId3") String questionId3, @Param("answer1") String answer1, @Param("answer2") String answer2, @Param("answer3") String answer3);

    @Select("select * from user_security_question_data where userId=#{userId}")
    UserSecurityInfo getUserSecurityById(String userId);

}